package scan.controller;


import org.apache.shardingsphere.transaction.core.TransactionType;
import org.apache.shardingsphere.transaction.core.TransactionTypeHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import scan.mapper.ShopMapper;
import scan.po.AdressPO;
import scan.util.IDWorker;

import java.net.UnknownHostException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;

@RestController
public class TestController {
    @Autowired
    private ShopMapper shopMapper;


    @RequestMapping("insert")
    public void insert() throws UnknownHostException, SQLException {

        Date date=new Date();
        Random r = new Random();

        for(long i=0;i<2;i++)
        {
            for(long j=0;j<16;j++)
            {
                List<AdressPO> orderPOList=new ArrayList<AdressPO>();
                AdressPO orderPO=new AdressPO();
                orderPO.setAddressId(IDWorker.getInstance("eshop_address").nextId());
                orderPO.setUserId(orderPO.getAddressId());
                orderPO.setCreateUserId(orderPO.getAddressId());
                orderPO.setModifyUserId(orderPO.getAddressId());
                orderPO.setProvinceCode(String.valueOf(r.nextInt(33)+1));
                orderPO.setCityCode(i);
                orderPO.setRegionCode(j);
                orderPO.setCreateTime(date);
                orderPO.setDetail("分库分表");
                orderPO.setAddressName("");
                orderPO.setModifyTime(date);
                orderPO.setCountryCode("");
                orderPO.setPhone("");
                orderPOList.add(orderPO);
                shopMapper.insert(orderPOList);
            }
        }
    }
}
